#!/usr/bin/env python
#encoding=utf8
"""
@描述：简单练习mongodb的读写
@作者：范红星
@日期：2014年11月21日 星期五
"""

import pymongo

if __name__ == "__main__":
	mongo = pymongo.MongoClient("xp-79",27017)
	db = mongo.UserDB
	# 注意文档结构的写法，以及嵌套/数组结构
	db.Users.save({"uname":"hongxingfan","school":["north east normal university","fu quan xioaxue"],"info":{"age":27,"addr":"baicheng"}})
	db.Users.save({"uname":"wenxiubi","school":["ha er bin shang ye daxue","ya bu li xiaoxue"],"info":{"age":27,"addr":"baicheng"}})

	cur = db.Users.find()
	# {}嵌套中的内容还是一个dict结构，注意嵌套/数组的访问方式
	for c in cur:
		print("%s\t%s\t%s\t%s" %(c.get("uname"),c.get("school")[1],c.get("info").get("age"),c.get("info").get("addr")))
	cur.close()
	mongo.close()

